package com.weipai.springboot.module.dao.impl;

import com.weipai.springboot.model.Customer;
import com.weipai.springboot.model.CustomerAddress;
import com.weipai.springboot.model.CustomerBank;
import com.weipai.springboot.model.CustomerInvoice;
import com.weipai.springboot.module.dao.CenterDao;
import com.weipai.springboot.module.dao.CustomerInvoiceDao;
import com.weipai.springboot.module.mapper.CustomerAddressMapper;
import com.weipai.springboot.module.mapper.CustomerBankMapper;
import com.weipai.springboot.module.mapper.CustomerInvoiceMapper;
import com.weipai.springboot.module.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/08/23 14:10
 */
@Repository
public class CenterDaoImpl implements CenterDao {

    @Autowired
    CustomerAddressMapper customerAddressMapper;
    @Autowired
    CustomerBankMapper customerBankMapper;
    @Autowired
    CustomerMapper customerMapper;
    @Autowired
    CustomerInvoiceMapper customerInvoiceMapper;
    
    //获取用户的收货地址
    @Override
    public List<CustomerAddress> getAddressByCustomerId(String id) {
        return customerAddressMapper.getAddressByCustomerId(id);
    }

    //获取收货地址详细信息
    @Override
    public CustomerAddress getAddressInfoById(String id) {
        return customerAddressMapper.getAddressInfoById(id);
    }

    //新增收货地址
    @Override
    public int saveAddress(CustomerAddress address) {
        return customerAddressMapper.insert(address);
    }

    //删除收货地址
    @Override
    public int deleteAddressById(String id) {
        return customerAddressMapper.deleteByPrimaryKey(id);
    }

    //新增银行卡
    @Override
    public int saveBank(CustomerBank customerBank) {
        return customerBankMapper.insert(customerBank);
    }

    //获取用户的银行卡
    @Override
    public List<CustomerBank> getBankByCustomerId(String id) {
        return customerBankMapper.getBankByCustomerId(id);
    }

    //删除银行卡
    @Override
    public int deleteBankById(String id) {
        return customerBankMapper.deleteByPrimaryKey(id);
    }

    //绑定支付宝账号
    @Override
    public int bindingAlipayAccount(String customerId, String alipayAccount, String realName) {
        return customerMapper.bindingAlipayAccount(customerId, alipayAccount, realName);
    }

    //修改收货地址
    @Override
    public int updateAddress(CustomerAddress address) {
        return customerAddressMapper.updateByPrimaryKeySelective(address);
    }

    //新增发票
    @Override
    public int saveInvoice(CustomerInvoice customerInvoice) {
        return customerInvoiceMapper.insertSelective(customerInvoice);
    }

    //修改发票
    @Override
    public int updateInvoice(String invoiceId, String companyName, String taxNumber, Integer isDeFault) {
        return customerInvoiceMapper.updateInvoice(invoiceId,companyName,taxNumber, isDeFault);
    }

    //获取用户的发票
    @Override
    public List<CustomerInvoice> invoiceList(String customerId) {
        return customerInvoiceMapper.invoiceList(customerId);
    }

    //删除发票信息
    @Override
    public int deleteInvoiceById(String id) {
        return customerInvoiceMapper.deleteByPrimaryKey(id);
    }

    //获取支付宝账号详细信息
    @Override
    public Map<String, Object> getAlipayAccountCustomerId(String customerId) {
        return customerMapper.getAlipayAccountCustomerId(customerId);
    }

    @Override
    public CustomerInvoice getInvoiceById(String invoiceId) {
        return customerInvoiceMapper.selectByPrimaryKey(invoiceId);
    }
}
